﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Osiptel.HECO.BE;
using System.Data.OracleClient;
using System.Data;

namespace Osiptel.HECO.DL
{
    public class PredefinidoDL
    {
        
        public int mInsertar(PredefinidoBE Predefinido)
        {
            
            try
            {
                Int32 id = 0;

                using (OracleCommand cmd = new OracleCommand())
                {
                    cmd.CommandText = "PKG_HECO_GLOBAL.SP_INSERTAR_PREDEFINIDO";
                    cmd.CommandType = CommandType.StoredProcedure;

                    OracleParameter prm1 = new OracleParameter("PUSUCRE", OracleType.VarChar);
                    OracleParameter prm2 = new OracleParameter("PIPREG", OracleType.VarChar);
                    OracleParameter prm3 = new OracleParameter("PIDPREDEF", OracleType.Int32);

                    prm1.Direction = ParameterDirection.Input;
                    prm2.Direction = ParameterDirection.Input;
                    prm3.Direction = ParameterDirection.Output;
                    
                    prm1.Value = Predefinido.UsuCre;
                    prm2.Value = Predefinido.IpReg;
                    prm3.Value = Predefinido.IdPredefinido;

                    cmd.Parameters.Add(prm1);
                    cmd.Parameters.Add(prm2);
                    cmd.Parameters.Add(prm3);
                    
                    using (DL_CONEXION NewConexion = new DL_CONEXION())
                    {
                        int ret = NewConexion.ejecutaSQL(cmd);
                        id = Convert.ToInt32(Convert.ToString(cmd.Parameters["PIDPREDEF"].Value));
                        return id;
                    }                    
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }       
    }
}
